import json
import sys
from jqdatasdk import auth, get_account_info


def main():
    try:
        raw = sys.stdin.read()
        if not raw:
            raise ValueError("未接收到任何输入参数")
        data = json.loads(raw)
        account = data.get("account")
        password = data.get("password")
        if not account or not password:
            raise ValueError("账号或密码不能为空")

        auth(account, password)
        info = get_account_info()

        print(json.dumps({
            "status": "success",
            "account": account,
            "permissions": info
        }, ensure_ascii=False))
    except json.JSONDecodeError:
        print(json.dumps({
            "status": "error",
            "message": "输入内容不是合法的 JSON 格式"
        }, ensure_ascii=False))
    except Exception as e:
        print(json.dumps({
            "status": "error",
            "message": f"聚宽账号校验失败：{e}"
        }, ensure_ascii=False))


if __name__ == "__main__":
    main()
